import { getCount } from "../services/homeApi";

const initData = {
  labelValues: ['-', '-', '-', '-'],
}

export default {
  namespace: "HomeModel",
  state: {
    ...initData,
  },
  effects: {
    * loadCount(action, { call, put }) {
      const { errCode, errMsg, datas } = yield call(getCount);
      if (errCode === 0) {
        const {
          countTodu = '-',
          countIssueNotice = '-',
          countProcessed = '-',
          countLaunchedProcess = '-',
        } = datas;
        yield put({
          type: "set/labelValues",
          payload: [
            countTodu,
            countIssueNotice,
            countProcessed,
            countLaunchedProcess,
          ],
        })
      }
      return { errCode, errMsg };
    },
  },
  reducers: {
    "set/labelValues": (state, { payload }) => ({
      ...state,
      labelValues: payload,
    }),
  },
}
